<template>
		<mt-index-list>
			<mt-index-section track-by="$index" v-for="index in cityIndex" :index="index">
					<mt-cell v-for="item in cityData[index]" @click="selectCityCardList(item.cityId,item.cityName)" :title="item.cityName" ca="P套餐卡_城市选择${{item.cityName}}"></mt-cell>
			</mt-index-section>
		</mt-index-list>
</template>

<script type="text/javascript">
	import Vue from 'vue';
	import Mint from 'mint-ui';
	import 'mint-ui/lib/style.css';

	Vue.use(Mint);

	import { IndexList, IndexSection } from 'mint-ui';
	Vue.component(IndexList.name, IndexList);
	Vue.component(IndexSection.name, IndexSection);
	//共用方法
	import common from '../../utils/common.js';
	export default{
		data () {
			return{
					cityIndex:[],
					cityData:[],
					catalogCode:''
			}

		},
		props:{
			defaultcityname:{
				type:String
			}
		},
		methods:{
			selectCityCardList:function(cityId, cityName){
				
				//禁止加载数据时触发下拉加载更多
				sessionStorage.pullDownStopType = false;
				
				var ajaxFlag = true,
					catalogCode = this.catalogCode || 1002764,
					cityId = cityId || 310100;

				localStorage.cardBuyCityId = cityId;

				if(ajaxFlag){

					ajaxFlag = false;

					this.$dispatch('cityShowBlock', 'area', cityName);

					this.$http.post(common.isdev()+'/cardList/queryCardList.htm', {
						currentPage:1, //当前页数
						catalogCode:catalogCode,//目录code
						cityId:cityId
						//channelType:'9'
					}).then(function ( d ) {

						var cardData = typeof d.body === 'object' ? d.body : JSON.parse(d.body);
						var cardListSkuCode = [];
						
						for(var i= 0; i < cardData.obj.r.length; i++){

							cardListSkuCode.push({"skuCode":cardData.obj.r[i].skuCode});

						}
						
						cardListSkuCode = JSON.stringify(cardListSkuCode);

						this.$http.post(common.isdev() + '/pricePrmtHandle/queryCxjMdsePricePrmts.htm', {
							cityId:cityId,
							skus:cardListSkuCode

						}).then(function(d){

							var skuData = typeof d.data === 'object' ? d.data.obj : JSON.parse(d.data).obj;

								for(var i = 0; i < cardData.obj.r.length; i++){

									for(var j = 0; j < skuData.length; j++){
										//回填价格
										if(cardData.obj.r[i].skuCode == skuData[j].skuCode){

											cardData.obj.r[i].cashPrice = skuData[j].cashPrice;

									}
									
								}//回填结束

								if(cardData.obj != null){
									//传递数据到 card-type-a 子组件
									this.$dispatch('cityCardRender', cardData.obj.r,cityName,cityId);
									
								}else{
									common.Toast(cardData.msg);
								}

							}
							ajaxFlag = true;

						},function(err) {

							common.Toast(err);

						});
						

					}, function ( error ) {
						console.log( error,'error',1);					
					});
				}
			}
		},
		events:{
			cityDatas: function(cityIndex, cityData,catalogCode){
				this.cityIndex = cityIndex;
				this.cityData = cityData;
				this.catalogCode = catalogCode;
			}
		}
	}
</script>
<style lang="scss" scoped>
	@import '../../assets/css/_functions.scss';
	@import '../../assets/css/_variables.scss';
</style>